import { FormSchema } from '@apps/antd-admin/src/components/Table';
import {render} from "@apps/antd-admin/src/hooks/render/renderUtils";
import {Api } from './api';

export const columns = [
  {
    title: '服务名称',
    dataIndex: 'categoryName',
    width: 200,
    align: 'left',
  },
  {
    title: '图标',
    dataIndex: 'categoryIcon',
    width: 50,
    customRender: render.renderImageAndNotNull,
  },

  {
    title: '启用',
    dataIndex: 'isShow',
    width: 120,
    align: 'center',
    rowKey: 'shopCategoryId',
    renderApi: Api.setIsShow,
    customRender: render.renderSwitch,
  },
  {
    title: '排序',
    dataIndex: 'sort',
    width: 50,
  }
];

const isDir = (type: string) => type === '0';
const isMenu = (type: string) => type === '1';
const isButton = (type: string) => type === '2';

export const searchFormSchema: FormSchema[] = [
  {
    field: 'categoryName',
    label: '服务名称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'shopCategoryId',
    label: '服务Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'categoryType',
    label: '类型',
    component: 'RadioButtonGroup',
    show:false,
    componentProps: {
      options: [
        { label: '目录', value: "0" },
        { label: '服务项', value: "1" },
        { label: '失物招领', value: "2" },
        { label: '爱心服务预约', value: "3" },
        { label: '轮椅服务', value: "4" },
        { label: '婴儿车借用', value: "5" },
      ],
    },
  },
  {
    field: 'categoryName',
    label: '服务名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'parentId',
    label: '上级服务',
    defaultValue: '0',
    component: 'TreeSelect',
    ifShow: ({ values }) => {
      return values.categoryType != '1' &&  values.categoryType != '0';
    },
    componentProps: {
      fieldNames: {
        label: 'categoryName',
        key: 'parentId',
        value: 'shopCategoryId',
      },
      getPopupContainer: () => document.body,
    },
  },

  {
    field: 'categoryIcon',
    label: '图标',
    component: 'ImageUpload',
    ifShow: ({ values }) => {
      return values.categoryType != '1' &&  values.categoryType != '0';
    },
    required: true
  },
  {
    label: '内容',
    field: 'categoryContent',
    component: 'TyEditor',
    ifShow: ({ values }) => {
      return values.categoryType == '1' || values.categoryType=='2' || values.categoryType=='3' || values.categoryType=='4' || values.categoryType=='5';
    },
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },
];
